<?php
/**
 * Created by PhpStorm.
 * User: YAN
 * Date: 2017/7/12
 * Time: 17:17
 */

namespace App\Components;


class GetUserInfo
{
    private $key = 'd41e3539ebb5356ba663c5111d1ad878';
    private $url = 'http://api.tjise.edu.cn/apiForTjise/api/stuBasicInfo.do?find';

    public function getUserByCode($code)
    {
        $post_data = array("xh" => $code, "key" => $this->key);
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $this->url);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
// post数据
        curl_setopt($ch, CURLOPT_POST, 1);
// post的变量
        curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);

        $output = curl_exec($ch);
        curl_close($ch);
        $result = \GuzzleHttp\json_decode($output);
//打印获得的数据
        if($result->success && $result->attr->count>0){
            return $result->attr->result[0];
        }else{
            return false;
        }


    }

}